﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.IO;

namespace Speedy
{
    public class Database : IDisposable
    {
        List<string> createQuery = null;
        public Database()
        {
            createQuery = new List<string>();
        }
        public void CreateTable(bool procCreate)
        {

            createQuery.Add("if NOT EXISTS (select * from INFORMATION_SCHEMA.TABLES where table_name = 'INVOICE_DETAILS') CREATE TABLE [dbo].[INVOICE_DETAILS]([ID] [int] IDENTITY(1,1) NOT NULL,[HEADER_ID] [int] NOT NULL,[LINE_NUMBER] [int] NOT NULL,[PROMO_ID] [int] NULL,[PRODUCT_CODE] [nvarchar](25) NULL,[AMOUNT] [float] NULL,	[PRICE] [float] NULL,	[DISCOUNT_RATE_1] [float] NULL,	[DISCOUNT_RATE_2] [float] NULL,	[DISCOUNT_RATE_3] [float] NULL,	[DISCOUNT_RATE_4] [float] NULL,	[DISCOUNT_RATE_5] [float] NULL,	[VAT_RATE] [int] NULL,	[DISCOUNT_TOTAL] [float] NULL,	[LINE_TOTAL] [float] NULL,	[LINE_NET_TOTAL] [float] NULL,	[CURRENCY] [int] NULL,	[CURRENCY_RATE] [float] NULL,[TEVKIFAT_TURU] [int] NULL,[TEVKIFAT_TUTARI] [float] NULL,[OTV_TUTARI] [float] NULL, CONSTRAINT [PK_INVOICE_DETAILS_1] PRIMARY KEY CLUSTERED (	[HEADER_ID] ASC,	[LINE_NUMBER] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY] ");
            createQuery.Add("if NOT EXISTS (select * from INFORMATION_SCHEMA.TABLES where table_name = 'MERCHANT') CREATE TABLE [dbo].[MERCHANT]([ID] [int] IDENTITY(1,1) NOT NULL,[CODE] [nvarchar](25) NOT NULL,[NAME] [nvarchar](25) NULL, CONSTRAINT [PK_MERCHANT] PRIMARY KEY CLUSTERED ([CODE] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY] ");
            createQuery.Add("if NOT EXISTS (select * from INFORMATION_SCHEMA.TABLES where table_name = 'PROMOTION_HEADER') CREATE TABLE [dbo].[PROMOTION_HEADER]([CODE] [int] NOT NULL,[NAME] [nvarchar](50) NULL,[TYPE] [tinyint] NULL,[DISCOUNT_RATE] [float] NULL,	[DISCOUNT_TOTAL] [float] NULL,	[LIMIT] [float] NULL,	[AMOUNT] [float] NULL,	[PROMOTION_AMOUNT] [float] NULL, CONSTRAINT [PK_PROMOTION_HEADER] PRIMARY KEY CLUSTERED (	[CODE] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY]");
            createQuery.Add("if NOT EXISTS (select * from INFORMATION_SCHEMA.TABLES where table_name = 'CUSTOMER_PROMOTION') CREATE TABLE [dbo].[CUSTOMER_PROMOTION]([ID] [int] IDENTITY(1,1) NOT NULL,[CUSTOMER_ID] [int] NOT NULL, [PROMOTION_ID] [int] NOT NULL, CONSTRAINT [PK_CUSTOMER_PROMOTION] PRIMARY KEY CLUSTERED (	[CUSTOMER_ID] ASC,	[PROMOTION_ID] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY] ");
            createQuery.Add("if NOT EXISTS (select * from INFORMATION_SCHEMA.TABLES where table_name = 'VEHICLE') CREATE TABLE [dbo].[VEHICLE]([ID] [int] IDENTITY(1,1) NOT NULL,[CODE] [nvarchar](25) NOT NULL,[NAME] [nvarchar](25) NULL,[MERCHANT_ID] [int] NULL, CONSTRAINT [PK_VEHICLE] PRIMARY KEY CLUSTERED (	[CODE] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY] ");
            createQuery.Add("if NOT EXISTS (select * from INFORMATION_SCHEMA.TABLES where table_name = 'PRODUCT_PROMOTION') CREATE TABLE [dbo].[PRODUCT_PROMOTION]( [ID] [int] IDENTITY(1,1) NOT NULL,[PROMOTION_ID] [int] NOT NULL, [PRODUCT_ID] [int] NOT NULL, [PRM_PRODUCT_ID] [int] NULL,	[CUSTOMER_ID] [int] NULL, CONSTRAINT [PK_PRODUCT_PROMOTION] PRIMARY KEY CLUSTERED (	[PROMOTION_ID] ASC,	[PRODUCT_ID] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY] ");
            createQuery.Add("if NOT EXISTS (select * from INFORMATION_SCHEMA.TABLES where table_name = 'MERCHANT_ROUTE') CREATE TABLE [dbo].[MERCHANT_ROUTE]([ID] [int] IDENTITY(1,1) NOT NULL,	[VISIT_NO] [int] NULL, [WEEK_NO] [int] NOT NULL, [DAY_NO] [int] NOT NULL,	[CUSTOMER_ID] [int] NOT NULL,	[MERCHANT_ID] [int] NOT NULL,	[ADDRESS_ID] [int] NOT NULL, CONSTRAINT [PK_MERCHANT_ROUTE] PRIMARY KEY CLUSTERED (	[WEEK_NO] ASC,	[DAY_NO] ASC,	[CUSTOMER_ID] ASC,	[MERCHANT_ID] ASC,[ADDRESS_ID] ASC) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY] ");
            createQuery.Add("if NOT EXISTS (select * from INFORMATION_SCHEMA.TABLES where table_name = 'DEVICE_DEFINITIONS') CREATE TABLE [dbo].[DEVICE_DEFINITIONS]([ID] [int] NOT NULL,[DESCRIPTION] [nvarchar](50) NULL,	[DEVICE_CODE] [nvarchar](50) NULL, [LICENCE_CODE] [nvarchar](50) NULL, CONSTRAINT [PK_DEVICE_DEFINITIONS] PRIMARY KEY CLUSTERED (	[ID] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY] ");
            createQuery.Add("if NOT EXISTS (select * from INFORMATION_SCHEMA.TABLES where table_name = 'DEVICE_PARAMETERS') CREATE TABLE [dbo].[DEVICE_PARAMETERS]([DEVICE_ID] [int] NOT NULL,	[PARAMETER_CODE] [varchar](25) NOT NULL, [PARAMETER_VALUE] [varchar](25) NOT NULL, CONSTRAINT [PK_DEVICE_PARAMETERS] PRIMARY KEY CLUSTERED (	[DEVICE_ID] ASC,	[PARAMETER_CODE] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY] ");
            createQuery.Add("if NOT EXISTS (select * from INFORMATION_SCHEMA.TABLES where table_name = 'TAX_RATE') CREATE TABLE [dbo].[TAX_RATE]([ID] [int] NOT NULL,	[NAME] [varchar](25) NULL,	[RATE] [int] NOT NULL, CONSTRAINT [PK_TAX_RATE] PRIMARY KEY CLUSTERED (	[ID] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY] ");
            createQuery.Add("if NOT EXISTS (select * from INFORMATION_SCHEMA.TABLES where table_name = 'INVOICE_HEADER') CREATE TABLE [dbo].[INVOICE_HEADER]([ID] [int] IDENTITY(1,1) NOT NULL,	[CREATE_DATE] [datetime] NULL, [UPDATE_DATE] [datetime] NULL, [SAVED_FLAG] [bit] NULL,	[SENT_FLAG] [bit] NULL,	[TERMINAL_ID] [varchar](25) NOT NULL,	[DOCUMENT_TYPE] [tinyint] NOT NULL,	[DOCUMENT_SERIES] [int] NOT NULL,	[DOCUMENT_SERIAL] [nvarchar](6) NULL,	[CUSTOMER_CODE] [nvarchar](25) NULL,	[DOCUMENT_DATE] [datetime] NULL,	[SUBTOTAL] [float] NULL,	[VAT_TOTAL] [float] NULL,	[DISCOUNT_TOTAL] [float] NULL,	[GENERAL_TOTAL] [float] NULL,	[INVOICE_SERIES] [nvarchar](6) NULL,	[INVOICE_NUMBER] [int] NULL,	[DESCRIPTION] [nvarchar](4000) NULL,	[STORE_CODE] [varchar](25) NULL,[RESPONSIBILITY_CODE] [nvarchar](25) NULL,[EXPLANATION] [nvarchar](250) NULL,[PRINTED] [tinyint] NULL,[TEVKIFAT] [float] NULL,[OTV] [float] NULL,[BELGE_NO] [varchar](25) NULL, CONSTRAINT [PK_INVOICE_HEADER] PRIMARY KEY CLUSTERED (	[TERMINAL_ID] ASC,	[DOCUMENT_TYPE] ASC,	[DOCUMENT_SERIES] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY] ");
            createQuery.Add("if NOT EXISTS (select * from INFORMATION_SCHEMA.TABLES where table_name = 'RECEIVING') CREATE TABLE [dbo].[RECEIVING]([ID] [int] NULL,[HEADER_ID] [int] NOT NULL,	[LINE_NUMBER] [smallint] NOT NULL,	[DOCUMENT_TYPE] [tinyint] NULL,	[CARD_NO] [nvarchar](25) NULL,	[DRAFT_TYPE] [tinyint] NULL,	[BANK] [nvarchar](25) NULL,	[BRANCH] [nvarchar](25) NULL,	[DRAW_DATE] [datetime] NULL,	[DRAWER] [nvarchar](50) NULL,	[DRAFT_NO] [nvarchar](25) NULL,	[ACCOUNT_CODE] [nvarchar](25) NULL,	[TOTAL] [float] NULL, CONSTRAINT [PK_RECEIVING_1] PRIMARY KEY CLUSTERED (	[HEADER_ID] ASC,	[LINE_NUMBER] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY] ");
            createQuery.Add("if NOT EXISTS (select * from INFORMATION_SCHEMA.TABLES where table_name = 'STOCK_MOVEMENT') CREATE TABLE [dbo].[STOCK_MOVEMENT]([ID] [int] IDENTITY(1,1) NOT NULL,[CREATE_DATE] [datetime] NULL, [UPDATE_DATE] [datetime] NULL, [SAVED_FLAG] [bit] NULL,	[SENT_FLAG] [bit] NULL,	[RETURN_TYPE] [int] NULL,	[DOCUMENT_DATE] [datetime] NULL,	[DESCRIPTION] [varchar](50) NULL,	[TERMINAL_ID] [int] NOT NULL,	[DOCUMENT_TYPE] [int] NOT NULL,	[DOCUMENT_SERIAL] [varchar](6) NOT NULL,	[DOCUMENT_NUMBER] [int] NOT NULL,	[LINE_NUMBER] [int] NOT NULL,	[CUSTOMER_CODE] [varchar](25) NULL,	[STORE_ID] [nvarchar](25) NULL,	[LOADING_STORE] [nvarchar](25) NULL,	[PRODUCT_CODE] [nvarchar](25) NULL,	[AMOUNT] [float] NULL,	[PRICE] [float] NULL,	[VAT_RATE] [int] NULL,	[DISCOUNT_TOTAL] [float] NULL,	[LINE_TOTAL] [float] NULL,	[LINE_NET_TOTAL] [float] NULL, CONSTRAINT [PK_STOCK_MOVEMENT] PRIMARY KEY CLUSTERED (	[TERMINAL_ID] ASC,	[DOCUMENT_TYPE] ASC,	[DOCUMENT_SERIAL] ASC,	[DOCUMENT_NUMBER] ASC,	[LINE_NUMBER] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY] ");

            createQuery.Add("if exists(Select * from sysobjects where xtype='p' and name='INVOICE_DETAILS_INS') DROP  PROCEDURE [dbo].[INVOICE_DETAILS_INS]");
            createQuery.Add("CREATE PROCEDURE [dbo].[INVOICE_DETAILS_INS] @HEADER_ID int,@LINE_NUMBER smallint, @PROMO_ID int,  @PRODUCT_CODE nvarchar(25),  @AMOUNT float, @PRICE float, @DISCOUNT_RATE_1 float, @DISCOUNT_RATE_2 float, @DISCOUNT_RATE_3 float, @DISCOUNT_RATE_4 float, @DISCOUNT_RATE_5 float, @VAT_RATE int, @DISCOUNT_TOTAL float,  @LINE_TOTAL float, @LINE_NET_TOTAL float, @CURRENCY int, @CURRENCY_RATE float,@TEVKIFAT_TURU int,@TEVKIFAT_TUTARI float,@OTV_TUTARI float AS if exists(SELECT HEADER_ID FROM INVOICE_DETAILS WHERE (HEADER_ID = @HEADER_ID) and (LINE_NUMBER=@LINE_NUMBER)) UPDATE INVOICE_DETAILS SET PROMO_ID = @PROMO_ID,PRODUCT_CODE = @PRODUCT_CODE, AMOUNT = @AMOUNT, PRICE = @PRICE, DISCOUNT_RATE_1 = @DISCOUNT_RATE_1, DISCOUNT_RATE_2 = @DISCOUNT_RATE_2,DISCOUNT_RATE_3 = @DISCOUNT_RATE_3,	DISCOUNT_RATE_4 = @DISCOUNT_RATE_4,	DISCOUNT_RATE_5 = @DISCOUNT_RATE_5,	VAT_RATE = @VAT_RATE,DISCOUNT_TOTAL = @DISCOUNT_TOTAL,LINE_TOTAL = @LINE_TOTAL,	LINE_NET_TOTAL = @LINE_NET_TOTAL,CURRENCY = @CURRENCY,	CURRENCY_RATE = @CURRENCY_RATE,TEVKIFAT_TURU=@TEVKIFAT_TURU,TEVKIFAT_TUTARI=@TEVKIFAT_TUTARI,OTV_TUTARI=@OTV_TUTARI	WHERE HEADER_ID = @HEADER_ID and LINE_NUMBER=@LINE_NUMBER ELSE 	INSERT INTO INVOICE_DETAILS (HEADER_ID,LINE_NUMBER,	PROMO_ID,PRODUCT_CODE, AMOUNT, PRICE, DISCOUNT_RATE_1, DISCOUNT_RATE_2,DISCOUNT_RATE_3,DISCOUNT_RATE_4,DISCOUNT_RATE_5,VAT_RATE, DISCOUNT_TOTAL,	LINE_TOTAL,	LINE_NET_TOTAL,	CURRENCY,CURRENCY_RATE,TEVKIFAT_TURU,TEVKIFAT_TUTARI,OTV_TUTARI)	VALUES (@HEADER_ID,@LINE_NUMBER,@PROMO_ID,	@PRODUCT_CODE,	@AMOUNT,@PRICE,	@DISCOUNT_RATE_1, @DISCOUNT_RATE_2,@DISCOUNT_RATE_3,@DISCOUNT_RATE_4,		@DISCOUNT_RATE_5, @VAT_RATE,@DISCOUNT_TOTAL,@LINE_TOTAL, @LINE_NET_TOTAL,@CURRENCY,	@CURRENCY_RATE,@TEVKIFAT_TURU,@TEVKIFAT_TUTARI,@OTV_TUTARI)");

            createQuery.Add("if exists(Select * from sysobjects where xtype='p' and name='INVOICE_HEADER_INS') DROP  PROCEDURE [dbo].[INVOICE_HEADER_INS]");
            createQuery.Add("CREATE PROCEDURE [dbo].[INVOICE_HEADER_INS] @ID INT OUTPUT, @CREATE_DATE datetime, @UPDATE_DATE datetime, @SAVED_FLAG bit, @SENT_FLAG int, @TERMINAL_ID varchar(25), @DOCUMENT_TYPE tinyint, @DOCUMENT_SERIES int, @DOCUMENT_SERIAL nvarchar(6), @CUSTOMER_CODE nvarchar(25), @DOCUMENT_DATE datetime, @SUBTOTAL float, @VAT_TOTAL float, @DISCOUNT_TOTAL float, @GENERAL_TOTAL float, @INVOICE_SERIES nvarchar(6),@INVOICE_NUMBER int,@DESCRIPTION nvarchar(4000),@STORE_CODE nvarchar(25),@RESPONSIBILITY_CODE nvarchar(25),@EXPLANATION nvarchar(250),@PRINTED tinyint,@TEVKIFAT float,@OTV float,@BELGE_NO varchar(25) AS BEGIN if exists (select ID from  INVOICE_HEADER where  TERMINAL_ID = @TERMINAL_ID AND DOCUMENT_TYPE = @DOCUMENT_TYPE AND DOCUMENT_SERIES = @DOCUMENT_SERIES) UPDATE INVOICE_HEADER SET CREATE_DATE = @CREATE_DATE, UPDATE_DATE = @UPDATE_DATE, SAVED_FLAG = @SAVED_FLAG, SENT_FLAG = @SENT_FLAG, CUSTOMER_CODE = @CUSTOMER_CODE, DOCUMENT_DATE = @DOCUMENT_DATE, SUBTOTAL = @SUBTOTAL,VAT_TOTAL = @VAT_TOTAL,	DISCOUNT_TOTAL = @DISCOUNT_TOTAL, GENERAL_TOTAL = @GENERAL_TOTAL,DOCUMENT_SERIAL = @DOCUMENT_SERIAL,INVOICE_SERIES=@INVOICE_SERIES,	INVOICE_NUMBER=@INVOICE_NUMBER,	DESCRIPTION=@DESCRIPTION,STORE_CODE=@STORE_CODE,RESPONSIBILITY_CODE=@RESPONSIBILITY_CODE,EXPLANATION=@EXPLANATION,PRINTED=@PRINTED,TEVKIFAT=@TEVKIFAT,OTV=@OTV,BELGE_NO=@BELGE_NO WHERE	TERMINAL_ID = @TERMINAL_ID AND DOCUMENT_TYPE = @DOCUMENT_TYPE AND DOCUMENT_SERIES = @DOCUMENT_SERIES ELSE INSERT INTO INVOICE_HEADER (CREATE_DATE,UPDATE_DATE,SAVED_FLAG,SENT_FLAG,	TERMINAL_ID,DOCUMENT_TYPE,DOCUMENT_SERIES,DOCUMENT_SERIAL,CUSTOMER_CODE,DOCUMENT_DATE,SUBTOTAL,	VAT_TOTAL,DISCOUNT_TOTAL,GENERAL_TOTAL,	INVOICE_SERIES,	INVOICE_NUMBER,	DESCRIPTION,STORE_CODE,RESPONSIBILITY_CODE,EXPLANATION,PRINTED,TEVKIFAT,OTV,BELGE_NO)	VALUES (@CREATE_DATE,@UPDATE_DATE,@SAVED_FLAG,@SENT_FLAG,@TERMINAL_ID,@DOCUMENT_TYPE,@DOCUMENT_SERIES,@DOCUMENT_SERIAL,	@CUSTOMER_CODE,	@DOCUMENT_DATE,	@SUBTOTAL,@VAT_TOTAL,@DISCOUNT_TOTAL,@GENERAL_TOTAL,@INVOICE_SERIES,@INVOICE_NUMBER,@DESCRIPTION,@STORE_CODE,@RESPONSIBILITY_CODE,@EXPLANATION,@PRINTED,@TEVKIFAT,@OTV,@BELGE_NO) SELECT @ID=ID FROM INVOICE_HEADER WHERE 	TERMINAL_ID = @TERMINAL_ID AND DOCUMENT_TYPE = @DOCUMENT_TYPE AND DOCUMENT_SERIES = @DOCUMENT_SERIES RETURN END");

            if (procCreate)
            {
                #region TERMINAL_NORMALSIPARIS_EKLE

                createQuery.Add("if exists(Select * from sysobjects where xtype='p' and name='TERMINAL_NORMALSIPARIS_EKLE')  DROP  PROCEDURE [dbo].[TERMINAL_NORMALSIPARIS_EKLE]\r\n");

                StringBuilder sb = new StringBuilder();
                sb.Append(" CREATE  PROCEDURE [dbo].[TERMINAL_NORMALSIPARIS_EKLE] \r\n");
                sb.Append(" @Evrak_Tarih DateTime, \r\n");
                sb.Append(" @Seri VarChar(5), \r\n");
                sb.Append(" @Sira int, \r\n");
                sb.Append(" @Satir Int, \r\n");
                sb.Append(" @Stok_kod VarChar(25), \r\n");
                sb.Append(" @Cari_kod VarChar(25), \r\n");
                sb.Append(" @Miktar Float, \r\n");
                sb.Append(" @GirisDepo int, \r\n");
                sb.Append(" @CikisDepo int, \r\n");
                sb.Append(" @plasiyer varchar(25), \r\n");
                sb.Append(" @srmerkez varchar(25), \r\n");
                sb.Append(" @kullanici varchar(25), \r\n");
                sb.Append(" @yekun Float, \r\n");
                sb.Append(" @isk1_tutar Float, \r\n");
                sb.Append(" @isk2_tutar Float, \r\n");
                sb.Append(" @isk3_tutar Float, \r\n");
                sb.Append(" @isk4_tutar Float, \r\n");
                sb.Append(" @isk5_tutar Float, \r\n");
                sb.Append(" @Kdv TinyInt, \r\n");
                sb.Append(" @Fiyat Float, \r\n");
                sb.Append(" @belge_no varchar(25), \r\n");
                sb.Append(" @firma_no int, \r\n");
                sb.Append(" @sube_no int, \r\n");
                sb.Append(" @doviz_cinsi int, \r\n");
                sb.Append(" @doviz_kur float \r\n");
                sb.Append(" AS \r\n");
                sb.Append(" DECLARE \r\n");
                sb.Append(" @Record_id int, \r\n");
                sb.Append(" @kdv_oran float, \r\n");
                sb.Append(" @kdv_tutar float \r\n");
                sb.Append(" set @kdv_oran=dbo.fn_VergiYuzde(@Kdv) \r\n");
                sb.Append(" set @kdv_tutar = (@yekun - (@isk1_tutar+@isk2_tutar+@isk3_tutar+@isk4_tutar+@isk5_tutar)) * @kdv_oran / 100 \r\n");
                sb.Append(" if exists(SELECT     sip_evrakno_seri  FROM         SIPARISLER  WHERE     (sip_evrakno_seri = @Seri) AND (sip_evrakno_sira =@Sira) AND (sip_satirno = @Satir) AND (sip_tip = 1) AND (sip_cins=0)) \r\n");
                sb.Append(" 	begin \r\n");
                sb.Append(" 		UPDATE SIPARISLER SET \r\n");
                sb.Append(" 									sip_lastup_user=@kullanici, sip_lastup_date=@Evrak_Tarih, sip_tarih=@Evrak_Tarih, sip_teslim_tarih=@Evrak_Tarih, sip_tip=1, sip_cins=0, sip_evrakno_seri=@Seri,   \r\n");
                sb.Append("                                        sip_evrakno_sira=@Sira, sip_satirno=@Satir, sip_belge_tarih=@Evrak_Tarih, sip_musteri_kod=@Cari_kod, sip_stok_kod=@Stok_kod, sip_b_fiyat= @Fiyat, sip_miktar=@Miktar, sip_teslim_miktar=0, sip_tutar=@yekun , sip_iskonto_1=@isk1_tutar, sip_iskonto_2=@isk2_tutar, sip_iskonto_3=@isk3_tutar, sip_iskonto_4=@isk4_tutar, sip_iskonto_5=@isk5_tutar , sip_vergi_pntr=@Kdv,sip_vergi=@kdv_tutar, \r\n");
                sb.Append("                                         sip_opno=0, sip_depono=@GirisDepo, sip_vergisiz_fl=0, sip_kapat_fl=0, sip_doviz_cinsi=@doviz_cinsi, sip_doviz_kuru=@doviz_kur, sip_alt_doviz_kuru=1, sip_adresno=0, sip_cagrilabilir_fl=1,   \r\n");
                sb.Append("                                        sip_prosiprecDbId=0, sip_prosiprecrecI=0, sip_durumu=0, sip_stalRecId_DBCno=0, sip_stalRecId_RECno=0, sip_planlananmiktar=0,sip_iskonto1=1, sip_iskonto2=1, sip_iskonto3=1, sip_iskonto4=1, sip_iskonto5=1,sip_stok_sormerk=@srmerkez,sip_cari_sormerk=@srmerkez,sip_belgeno=@belge_no,sip_firmano=@firma_no,sip_subeno=@sube_no,sip_harekettipi=0 \r\n");
                sb.Append(" 		WHERE     (sip_evrakno_seri = @Seri) AND (sip_evrakno_sira =@Sira) AND (sip_satirno = @Satir) AND (sip_tip = 1) AND (sip_cins=0) \r\n");
                sb.Append(" 	end \r\n");
                sb.Append(" else \r\n");
                sb.Append(" 	begin \r\n");
                sb.Append(" 		INSERT INTO SIPARISLER   \r\n");
                sb.Append("                                       (sip_RECid_DBCno, sip_RECid_RECno, sip_SpecRECno, sip_iptal, sip_fileid, sip_hidden, sip_kilitli, sip_checksum, sip_create_user,   \r\n");
                sb.Append("                                        sip_create_date, sip_lastup_user, sip_lastup_date, sip_tarih, sip_teslim_tarih, sip_tip, sip_cins, sip_evrakno_seri,   \r\n");
                sb.Append("                                        sip_evrakno_sira, sip_satirno, sip_belge_tarih, sip_musteri_kod, sip_stok_kod, sip_b_fiyat, sip_miktar, sip_teslim_miktar, sip_tutar , sip_iskonto_1, sip_iskonto_2, sip_iskonto_3, sip_iskonto_4, sip_iskonto_5, sip_vergi_pntr,sip_vergi, \r\n");
                sb.Append("                                         sip_opno, sip_depono, sip_vergisiz_fl, sip_kapat_fl, sip_doviz_cinsi, sip_doviz_kuru, sip_alt_doviz_kuru, sip_adresno, sip_cagrilabilir_fl,   \r\n");
                sb.Append("                                        sip_prosiprecDbId, sip_prosiprecrecI, sip_durumu, sip_stalRecId_DBCno, sip_stalRecId_RECno, sip_planlananmiktar,sip_iskonto1, sip_iskonto2, sip_iskonto3, sip_iskonto4, sip_iskonto5,sip_stok_sormerk,sip_cari_sormerk,sip_belgeno,sip_firmano,sip_subeno,sip_harekettipi)  \r\n");
                sb.Append("                         VALUES     (0,0, 0, 0, 21, 0, 0, 0, @kullanici,@Evrak_Tarih, @kullanici,@Evrak_Tarih,@Evrak_Tarih,@Evrak_Tarih, 1, 0, @Seri,@Sira,@Satir,@Evrak_Tarih,@Cari_kod,@Stok_kod, @Fiyat  , @Miktar  , 0, @yekun  , @isk1_tutar  , @isk2_tutar  , @isk3_tutar  , @isk4_tutar  , @isk5_tutar  ,@Kdv,@kdv_tutar, 0,@GirisDepo, 0, 0, @doviz_cinsi, @doviz_kur, 1, 0, 1, 0, 0, 0, 0, 0, 0,1,1,1,1,1,@srmerkez,@srmerkez,@belge_no,@firma_no,@sube_no,0) \r\n");
                sb.Append(" 		SELECT @Record_id=SCOPE_IDENTITY() \r\n");
                sb.Append(" 		UPDATE    SIPARISLER    SET   sip_RECid_RECno = @Record_id  WHERE    sip_RECno = @Record_id \r\n");
                sb.Append(" 	end \r\n");

                createQuery.Add(sb.ToString());
                #endregion

                #region TERMINAL_SUBE_SIPARIS_EKLE
                createQuery.Add("if exists(Select * from sysobjects where xtype='p' and name='TERMINAL_SUBE_SIPARIS_EKLE')  DROP  PROCEDURE [dbo].[TERMINAL_SUBE_SIPARIS_EKLE]\r\n");

                sb = new StringBuilder();
                sb.Append(" CREATE   PROCEDURE [dbo].[TERMINAL_SUBE_SIPARIS_EKLE] \r\n");
                sb.Append(" @Tip TinyInt, \r\n");
                sb.Append(" @Cins TinyInt, \r\n");
                sb.Append(" @Normal_iade TinyInt, \r\n");
                sb.Append(" @Evrak_Tip TinyInt, \r\n");
                sb.Append(" @Evrak_Tarih DateTime, \r\n");
                sb.Append(" @Seri VarChar(5), \r\n");
                sb.Append(" @Sira int, \r\n");
                sb.Append(" @Satir Int, \r\n");
                sb.Append(" @Stok_kod VarChar(25), \r\n");
                sb.Append(" @Cari_kod VarChar(25), \r\n");
                sb.Append(" @Miktar Float, \r\n");
                sb.Append(" @GirisDepo int, \r\n");
                sb.Append(" @CikisDepo int, \r\n");
                sb.Append(" @plasiyer varchar(25), \r\n");
                sb.Append(" @srmerkez varchar(25), \r\n");
                sb.Append(" @kullanici varchar(25), \r\n");
                sb.Append(" @yekun Float, \r\n");
                sb.Append(" @isk1_tutar Float, \r\n");
                sb.Append(" @isk2_tutar Float, \r\n");
                sb.Append(" @isk3_tutar Float, \r\n");
                sb.Append(" @isk4_tutar Float, \r\n");
                sb.Append(" @isk5_tutar Float, \r\n");
                sb.Append(" @Kdv TinyInt, \r\n");
                sb.Append(" @Fiyat Float, \r\n");
                sb.Append(" @belge_no varchar(25), \r\n");
                sb.Append(" @firma_no int, \r\n");
                sb.Append(" @sube_no int \r\n");
                sb.Append(" AS \r\n");
                sb.Append(" DECLARE \r\n");
                sb.Append(" @Record_id int \r\n");
                sb.Append(" if exists(SELECT      ssip_evrakno_seri  FROM       DEPOLAR_ARASI_SIPARISLER   WHERE     ( ssip_evrakno_seri = @Seri) AND ( ssip_evrakno_sira =@Sira) AND ( ssip_satirno = @Satir) ) \r\n");
                sb.Append(" 	begin \r\n");
                sb.Append(" 		UPDATE DEPOLAR_ARASI_SIPARISLER   SET \r\n");
                sb.Append(" 							ssip_lastup_user=@kullanici, ssip_lastup_date=@Evrak_Tarih, ssip_tarih=@Evrak_Tarih, ssip_teslim_tarih=@Evrak_Tarih,   \r\n");
                sb.Append("                            ssip_evrakno_seri= @Seri, ssip_evrakno_sira=@Sira, ssip_satirno=@Satir, ssip_belge_tarih=@Evrak_Tarih, ssip_stok_kod=@Stok_kod, ssip_miktar=@Miktar, ssip_b_fiyat=@Fiyat, ssip_tutar=@yekun, ssip_teslim_miktar=0,   \r\n");
                sb.Append("                            ssip_girdepo=@GirisDepo, ssip_cikdepo=@CikisDepo, ssip_kapat_fl=0,ssip_special1='',ssip_special2='',ssip_special3='',ssip_aciklama='',ssip_belgeno=@belge_no,ssip_firmano=@firma_no,ssip_subeno=@sube_no \r\n");
                sb.Append(" 		WHERE     (ssip_evrakno_seri = @Seri) AND (ssip_evrakno_sira =@Sira) AND (ssip_satirno = @Satir)  \r\n");
                sb.Append(" 	end \r\n");
                sb.Append(" else \r\n");
                sb.Append(" 	begin \r\n");
                sb.Append(" 		INSERT INTO DEPOLAR_ARASI_SIPARISLER  \r\n");
                sb.Append("                            (ssip_RECid_DBCno, ssip_RECid_RECno, ssip_SpecRECno, ssip_iptal, ssip_fileid, ssip_hidden, ssip_kilitli, ssip_checksum,  \r\n");
                sb.Append("                            ssip_create_user, ssip_create_date, ssip_lastup_user, ssip_lastup_date, ssip_tarih, ssip_teslim_tarih,   \r\n");
                sb.Append("                            ssip_evrakno_seri, ssip_evrakno_sira, ssip_satirno, ssip_belge_tarih, ssip_stok_kod, ssip_miktar, ssip_b_fiyat, ssip_tutar, ssip_teslim_miktar,   \r\n");
                sb.Append("                            ssip_girdepo, ssip_cikdepo, ssip_kapat_fl,ssip_special1,ssip_special2,ssip_special3,ssip_aciklama,ssip_belgeno,ssip_firmano,ssip_subeno)  \r\n");
                sb.Append("                         VALUES     (0,0,0, 0, 86, 0, 0, 0, @kullanici,@Evrak_Tarih, @kullanici,@Evrak_Tarih,@Evrak_Tarih,@Evrak_Tarih, @Seri,@Sira ,@Satir,@Evrak_Tarih,@Stok_kod, @Miktar  , @Fiyat  , @yekun  , 0,@GirisDepo,@CikisDepo,0,'','' ,'','',@belge_no,@firma_no,@sube_no) \r\n");
                sb.Append(" SELECT @Record_id=SCOPE_IDENTITY() \r\n");
                sb.Append(" 		UPDATE    DEPOLAR_ARASI_SIPARISLER  SET   ssip_RECid_RECno = @Record_id  WHERE    ssip_RECno = @Record_id \r\n");
                sb.Append(" 	end \r\n");

                createQuery.Add(sb.ToString());
                #endregion

                #region TERMINAL_SHAR_EKLE
                createQuery.Add("if exists(Select * from sysobjects where xtype='p' and name='TERMINAL_SHAR_EKLE')  DROP  PROCEDURE [dbo].[TERMINAL_SHAR_EKLE]\r\n");

                sb = new StringBuilder();
                sb.Append(" CREATE   PROCEDURE [dbo].[TERMINAL_SHAR_EKLE] \r\n");
                sb.Append(" @Tip TinyInt, \r\n");
                sb.Append(" @Cins TinyInt, \r\n");
                sb.Append(" @Normal_iade TinyInt, \r\n");
                sb.Append(" @Evrak_Tip TinyInt, \r\n");
                sb.Append(" @Evrak_Tarih DateTime, \r\n");
                sb.Append(" @Seri VarChar(5), \r\n");
                sb.Append(" @Sira int, \r\n");
                sb.Append(" @Satir Int, \r\n");
                sb.Append(" @Stok_kod VarChar(25), \r\n");
                sb.Append(" @Cari_kod VarChar(25), \r\n");
                sb.Append(" @Miktar Float, \r\n");
                sb.Append(" @GirisDepo int, \r\n");
                sb.Append(" @CikisDepo int, \r\n");
                sb.Append(" @odeme int, \r\n");
                sb.Append(" @plasiyer varchar(25), \r\n");
                sb.Append(" @srmerkez varchar(25), \r\n");
                sb.Append(" @kullanici varchar(25), \r\n");
                sb.Append(" @yekun Float, \r\n");
                sb.Append(" @isk1_tutar Float, \r\n");
                sb.Append(" @isk2_tutar Float, \r\n");
                sb.Append(" @isk3_tutar Float, \r\n");
                sb.Append(" @isk4_tutar Float, \r\n");
                sb.Append(" @isk5_tutar Float, \r\n");
                sb.Append(" @Kdv TinyInt, \r\n");
                sb.Append(" @Ref_rec Int, \r\n");
                sb.Append(" @Ref_dbc Int, \r\n");
                sb.Append(" @Fiyat Float, \r\n");
                sb.Append(" @belge_no varchar(25), \r\n");
                sb.Append(" @firma_no int, \r\n");
                sb.Append(" @sube_no int, \r\n");
                sb.Append(" @adres_rec int, \r\n");
                sb.Append(" @tevkifat_tip int \r\n");
                sb.Append(" AS \r\n");
                sb.Append(" DECLARE \r\n");
                sb.Append(" @Record_id int, \r\n");
                sb.Append(" @kdv_oran float, \r\n");
                sb.Append(" @kdv_tutar float, \r\n");
                sb.Append(" @sube_sip_rec int, \r\n");
                sb.Append(" @sube_sip_dbc int, \r\n");
                sb.Append(" @norm_sip_rec int, \r\n");
                sb.Append(" @norm_sip_dbc int, \r\n");
                sb.Append(" @adres_no int \r\n");
                sb.Append(" set @kdv_oran=dbo.fn_VergiYuzde(@Kdv) \r\n");
                sb.Append(" set @kdv_tutar = (@yekun - (@isk1_tutar+@isk2_tutar+@isk3_tutar+@isk4_tutar+@isk5_tutar)) * @kdv_oran / 100 \r\n");
                sb.Append(" set @sube_sip_rec=0 \r\n");
                sb.Append(" set @sube_sip_dbc=0 \r\n");
                sb.Append(" set @norm_sip_rec=@Ref_rec \r\n");
                sb.Append(" set @norm_sip_dbc=@Ref_dbc \r\n");
                sb.Append(" SELECT     @adres_no=adr_adres_no  FROM         CARI_HESAP_ADRESLERI WHERE     (adr_RECno = @adres_rec) \r\n");
                sb.Append(" if @adres_no is null set @adres_no=1 \r\n");
                sb.Append(" if @Tip= 2 and @Cins= 6 and @Evrak_Tip= 2 /*depo sevk ise*/ \r\n");
                sb.Append(" begin \r\n");
                sb.Append(" 		set @sube_sip_rec=@Ref_rec \r\n");
                sb.Append(" 		set @sube_sip_dbc=@Ref_dbc \r\n");
                sb.Append(" 		set @norm_sip_rec=0 \r\n");
                sb.Append(" 		set @norm_sip_dbc=0 \r\n");
                sb.Append(" end \r\n");
                sb.Append(" if exists(SELECT     sth_evrakno_seri  FROM         STOK_HAREKETLERI  WHERE     (sth_evrakno_seri = @Seri) AND (sth_evrakno_sira =@Sira) AND (sth_satirno = @Satir) AND (sth_evraktip = @Evrak_Tip) AND (sth_tip=@Tip) AND (sth_cins=@Cins) and (sth_normal_iade=@Normal_iade)) \r\n");
                sb.Append(" 	begin \r\n");
                sb.Append(" 		UPDATE STOK_HAREKETLERI SET \r\n");
                sb.Append(" 							  sth_lastup_user=@kullanici, sth_lastup_date=@Evrak_Tarih, sth_tarih=@Evrak_Tarih, sth_tip=@Tip, sth_cins=@Cins, sth_normal_iade=@Normal_iade, sth_belge_tarih=@Evrak_Tarih,  \r\n");
                sb.Append(" 							  sth_stok_kod=@Stok_kod, sth_cari_kodu=@Cari_kod, sth_plasiyer_kodu=@plasiyer, sth_kur_tarihi=@Evrak_Tarih, sth_miktar=@Miktar, sth_miktar2=@Miktar, sth_birim_pntr=1, sth_tutar=@yekun, sth_iskonto1=@isk1_tutar, sth_iskonto2=@isk2_tutar, sth_iskonto3=@isk3_tutar,  \r\n");
                sb.Append(" 							  sth_iskonto4=@isk4_tutar, sth_iskonto5=@isk5_tutar, sth_vergi_pntr=@Kdv,sth_vergi=@kdv_tutar, sth_odeme_op=@odeme, sth_sip_recid_dbcno=@norm_sip_dbc, sth_sip_recid_recno=@norm_sip_rec, sth_giris_depo_no=@GirisDepo, sth_cikis_depo_no=@CikisDepo,  \r\n");
                sb.Append(" 							  sth_malkbl_sevk_tarihi=@Evrak_Tarih, sth_cari_srm_merkezi=@srmerkez, sth_stok_srm_merkezi=@srmerkez, sth_fis_tarihi=@Evrak_Tarih, sth_maliyet_ana=@Fiyat, sth_maliyet_alternatif=@Fiyat, sth_maliyet_orjinal=@Fiyat, sth_vardiya_tarihi=@Evrak_Tarih,sth_subesip_recid_dbcno=@sube_sip_dbc,sth_subesip_recid_recno=@sube_sip_rec,sth_belge_no=@belge_no, \r\n");
                sb.Append(" 							  sth_firmano=@firma_no,sth_subeno=@sube_no,sth_Tevkifat_turu=@tevkifat_tip \r\n");
                sb.Append(" 		WHERE     (sth_evrakno_seri = @Seri) AND (sth_evrakno_sira =@Sira) AND (sth_satirno = @Satir) AND (sth_evraktip = @Evrak_Tip AND (sth_tip=@Tip) AND (sth_cins=@Cins) and (sth_normal_iade=@Normal_iade)) \r\n");
                sb.Append(" 	end \r\n");
                sb.Append(" else \r\n");
                sb.Append(" 	begin \r\n");
                sb.Append(" 		INSERT INTO STOK_HAREKETLERI \r\n");
                sb.Append(" 		 (sth_RECid_DBCno,sth_RECid_RECno,sth_SpecRECno,sth_iptal,sth_fileid,sth_hidden,sth_kilitli,sth_degisti,sth_checksum,sth_create_user,sth_create_date,sth_lastup_user,sth_lastup_date,sth_special1,sth_special2,sth_special3,sth_firmano,sth_subeno,sth_tarih,sth_tip,sth_cins,sth_normal_iade,sth_evraktip,sth_evrakno_seri,sth_evrakno_sira,sth_satirno,sth_belge_no,sth_belge_tarih,sth_stok_kod,sth_isk_mas1,sth_isk_mas2,sth_isk_mas3,sth_isk_mas4,sth_isk_mas5,sth_isk_mas6,sth_isk_mas7,sth_isk_mas8,sth_isk_mas9,sth_isk_mas10,sth_sat_iskmas1,sth_sat_iskmas2,sth_sat_iskmas3,sth_sat_iskmas4,sth_sat_iskmas5,sth_sat_iskmas6,sth_sat_iskmas7,sth_sat_iskmas8,sth_sat_iskmas9,sth_sat_iskmas10,sth_pos_satis,sth_cari_cinsi,sth_cari_kodu,sth_cari_grup_no,sth_isemri_gider_kodu,sth_ismerkezi_kodu,sth_plasiyer_kodu,sth_kur_tarihi,sth_har_doviz_cinsi,sth_har_doviz_kuru,sth_alt_doviz_kuru,sth_stok_doviz_cinsi,sth_stok_doviz_kuru,sth_miktar,sth_miktar2,sth_birim_pntr,sth_tutar,sth_iskonto1,sth_iskonto2,sth_iskonto3,sth_iskonto4,sth_iskonto5,sth_iskonto6,sth_masraf1,sth_masraf2,sth_masraf3,sth_masraf4,sth_vergi_pntr,sth_vergi,sth_masraf_vergi_pntr,sth_masraf_vergi,sth_netagirlik,sth_odeme_op,sth_aciklama,sth_sip_recid_dbcno,sth_sip_recid_recno,sth_fat_recid_dbcno,sth_fat_recid_recno,sth_giris_depo_no,sth_cikis_depo_no,sth_malkbl_sevk_tarihi,sth_cari_srm_merkezi,sth_stok_srm_merkezi,sth_fis_tarihi,sth_fis_sirano,sth_vergisiz_fl,sth_maliyet_ana,sth_maliyet_alternatif,sth_maliyet_orjinal,sth_adres_no,sth_parti_kodu,sth_lot_no,sth_kons_recid_dbcno,sth_kons_recid_recno,sth_vardiya_tarihi,sth_vardiya_no,sth_satistipi,sth_proje_kodu,sth_ihracat_kredi_kodu,sth_exim_kodu,sth_otv_pntr,sth_otv_vergi,sth_bkm_recid_dbcno,sth_bkm_recid_recno,sth_karsikons_recid_dbcno,sth_karsikons_recid_recno,sth_iade_evrak_seri,sth_iade_evrak_sira,sth_diib_belge_no,sth_diib_satir_no,sth_mensey_ulke_tipi,sth_mensey_ulke_kodu,sth_brutagirlik,sth_halrehmiktari,sth_halrehfiyati,sth_halsandikmiktari,sth_halsandikfiyati,sth_halsandikkdvtutari,sth_disticaret_turu,sth_otvtutari,sth_otvvergisiz_fl,sth_direkt_iscilik_1,sth_direkt_iscilik_2,sth_direkt_iscilik_3,sth_direkt_iscilik_4,sth_direkt_iscilik_5,sth_genel_uretim_1,sth_genel_uretim_2,sth_genel_uretim_3,sth_genel_uretim_4,sth_genel_uretim_5,sth_yat_tes_kodu,sth_oiv_pntr,sth_oiv_vergi,sth_oivvergisiz_fl,sth_subesip_recid_dbcno,sth_subesip_recid_recno,sth_Tevkifat_turu) \r\n");
                sb.Append(" 		VALUES (0,0,0,0,16,0,0,0,0,@kullanici,@Evrak_Tarih,@kullanici,@Evrak_Tarih,'','','',@firma_no,@sube_no,@Evrak_Tarih,@Tip,@Cins,@Normal_iade,@Evrak_Tip,@Seri,@Sira,@Satir,@belge_no,@Evrak_Tarih,@Stok_kod,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,@Cari_kod,0,'','',@plasiyer,@Evrak_Tarih,0,1,1,0,1, @Miktar  , @Miktar  ,1, @yekun   ,@isk1_tutar,@isk2_tutar,@isk3_tutar,@isk4_tutar,@isk5_tutar,0,0,0,0,0,@Kdv,@kdv_tutar,0,0,0,@odeme,'',@norm_sip_dbc,@norm_sip_rec,0,0,@GirisDepo,@CikisDepo,@Evrak_Tarih,@srmerkez,@srmerkez, @Evrak_Tarih,0,0, @Fiyat  , @Fiyat  , @Fiyat  ,@adres_no,'',0,0,0,@Evrak_Tarih,0,0,'','','',0,0,0,0,0,0,'',0,'',0,0,'',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'',0,0,0,@sube_sip_dbc,@sube_sip_rec,@tevkifat_tip) \r\n");
                sb.Append(" 		SELECT @Record_id=SCOPE_IDENTITY() \r\n");
                sb.Append(" 		UPDATE    STOK_HAREKETLERI  SET   sth_RECid_RECno = SCOPE_IDENTITY()  WHERE    sth_RECno = SCOPE_IDENTITY() \r\n");
                sb.Append(" 	end \r\n");
                sb.Append(" /*sipariş teslim miktarı*/ \r\n");
                sb.Append(" if @Tip= 2 and @Cins= 6 and @Evrak_Tip= 2 and @sube_sip_rec > 0 \r\n");
                sb.Append(" 	begin  \r\n");
                sb.Append(" 		UPDATE DEPOLAR_ARASI_SIPARISLER SET ssip_teslim_miktar =ssip_teslim_miktar + @Miktar  WHERE (ssip_RECid_DBCno = 0) AND (ssip_RECid_RECno = @sube_sip_rec) \r\n");
                sb.Append(" 	end \r\n");
                sb.Append(" else  \r\n");
                sb.Append(" 	begin \r\n");
                sb.Append(" 		if @norm_sip_rec > 0 \r\n");
                sb.Append(" 			UPDATE SIPARISLER SET sip_teslim_miktar =sip_teslim_miktar + @Miktar  WHERE (sip_RECid_DBCno = 0) AND (sip_RECid_RECno = @norm_sip_rec) \r\n");
                sb.Append(" 	end \r\n");

                createQuery.Add(sb.ToString());
                #endregion

                #region TERMINAL_PROFORMA_SIPARISLER_EKLE
                createQuery.Add("if exists(Select * from sysobjects where xtype='p' and name='TERMINAL_PROFORMA_SIPARISLER_EKLE')  DROP  PROCEDURE [dbo].[TERMINAL_PROFORMA_SIPARISLER_EKLE]\r\n");

                sb = new StringBuilder();
                sb.Append(" CREATE   PROCEDURE [dbo].[TERMINAL_PROFORMA_SIPARISLER_EKLE] \r\n");
                sb.Append(" @Tip TinyInt, \r\n");
                sb.Append(" @Cins TinyInt, \r\n");
                sb.Append(" @Normal_iade TinyInt, \r\n");
                sb.Append(" @Evrak_Tip TinyInt, \r\n");
                sb.Append(" @Evrak_Tarih DateTime, \r\n");
                sb.Append(" @Seri VarChar(5), \r\n");
                sb.Append(" @Sira int, \r\n");
                sb.Append(" @Satir Int, \r\n");
                sb.Append(" @Stok_kod VarChar(25), \r\n");
                sb.Append(" @Cari_kod VarChar(25), \r\n");
                sb.Append(" @Miktar Float, \r\n");
                sb.Append(" @GirisDepo int, \r\n");
                sb.Append(" @CikisDepo int, \r\n");
                sb.Append(" @plasiyer varchar(25), \r\n");
                sb.Append(" @srmerkez varchar(25), \r\n");
                sb.Append(" @kullanici varchar(25), \r\n");
                sb.Append(" @yekun Float, \r\n");
                sb.Append(" @isk1_tutar Float, \r\n");
                sb.Append(" @isk2_tutar Float, \r\n");
                sb.Append(" @isk3_tutar Float, \r\n");
                sb.Append(" @isk4_tutar Float, \r\n");
                sb.Append(" @isk5_tutar Float, \r\n");
                sb.Append(" @Kdv TinyInt, \r\n");
                sb.Append(" @Fiyat Float, \r\n");
                sb.Append(" @belge_no varchar(25), \r\n");
                sb.Append(" @firma_no int, \r\n");
                sb.Append(" @sube_no int \r\n");
                sb.Append(" AS \r\n");
                sb.Append(" DECLARE \r\n");
                sb.Append(" @Record_id int, \r\n");
                sb.Append(" @kdv_oran float, \r\n");
                sb.Append(" @kdv_tutar float \r\n");
                sb.Append(" set @kdv_oran=dbo.fn_VergiYuzde(@Kdv) \r\n");
                sb.Append(" set @kdv_tutar = (@yekun - (@isk1_tutar+@isk2_tutar+@isk3_tutar+@isk4_tutar+@isk5_tutar)) * @kdv_oran / 100 \r\n");
                sb.Append(" if exists(SELECT      pro_evrakno_seri  FROM       PROFORMA_SIPARISLER   WHERE     ( pro_evrakno_seri = @Seri) AND ( pro_evrakno_sira =@Sira) AND ( pro_satirno = @Satir )AND (pro_tipi = @Evrak_Tip) AND (pro_cinsi=@Cins) ) \r\n");
                sb.Append(" 	begin \r\n");
                sb.Append(" 		UPDATE PROFORMA_SIPARISLER   SET \r\n");
                sb.Append(" 									pro_lastup_user=@kullanici, pro_lastup_date=@Evrak_Tarih, pro_special1='',pro_special2='',pro_special3='',pro_firmano=@firma_no,pro_subeno=@sube_no,pro_tarihi=@Evrak_Tarih,pro_testarihi=@Evrak_Tarih,pro_tipi=1,pro_cinsi=2, pro_evrakno_seri=@Seri,   \r\n");
                sb.Append("                                        pro_evrakno_sira=@Sira, pro_satirno=@Satir, pro_belge_tarihi=@Evrak_Tarih,pro_saticikodu='',pro_mustkodu=@Cari_kod, pro_stokkodu=@Stok_kod, pro_bfiyati=@Fiyat, pro_miktar=@Miktar,pro_birim_pntr=1, pro_tesmiktari=0, pro_tutari=@yekun  , pro_iskonto1=@isk1_tutar, pro_iskonto2=@isk2_tutar, pro_iskonto3=@isk3_tutar, pro_iskonto4=@isk4_tutar, pro_iskonto5=@isk5_tutar,pro_iskonto6=0,pro_masraf1=0,pro_masraf2=0,pro_masraf3=0,pro_masraf4=0, pro_vergipntr=@Kdv,pro_vergi=@kdv_tutar, \r\n");
                sb.Append("                                        pro_masrafvergipntr=0,pro_masrafvergi=0,pro_opno=0,pro_aciklama='', pro_depono=@GirisDepo, pro_onaylayanKul_no=0,pro_vergisiz=0, pro_kapat=0,pro_cari_sormerk=@srmerkez,pro_stok_sormerk=@srmerkez, pro_dovizcinsi=0, pro_dovizkuru=1, pro_altdovizkuru=1, pro_adresno=1,pro_teslimturu='', pro_cagrilabilir_fl=1,   \r\n");
                sb.Append("                                        pro_sipDbID=0, pro_sipRecID=0, pro_isk_mas_1=0,pro_isk_mas_2=1,pro_isk_mas_3=1,pro_isk_mas_4=1,pro_isk_mas_5=1,pro_isk_mas_6=1,pro_isk_mas_7=1,pro_isk_mas_8=1,pro_isk_mas_9=1,pro_isk_mas_10=1,pro_sat_isk_mas1=0,pro_sat_isk_mas2=0,pro_sat_isk_mas3=0,pro_sat_isk_mas4=0,pro_sat_isk_mas5=0,pro_sat_isk_mas6=0,pro_sat_isk_mas7=0,pro_sat_isk_mas8=0,pro_sat_isk_mas9=0,pro_sat_isk_mas10=0, \r\n");
                sb.Append("                                       pro_aciklama2='',pro_Exp_Imp_Kodu='',pro_karoani=0,pro_durumu=0, pro_stalRecId_DBCno=0, pro_stalRecId_RECno=0, pro_planlananmiktar=0,pro_teklifRecId_DBCno=0,pro_teklifRecId_RECno=0,pro_parti_kodu='',pro_lot_no=0,pro_projekodu='',pro_belge_no=@belge_no \r\n");
                sb.Append(" WHERE     (pro_evrakno_seri = @Seri) AND (pro_evrakno_sira =@Sira) AND (pro_satirno = @Satir) AND (pro_tipi = @Evrak_Tip) AND (pro_cinsi=@Cins) \r\n");
                sb.Append(" 	end \r\n");
                sb.Append(" else \r\n");
                sb.Append(" 	begin \r\n");
                sb.Append(" 		INSERT INTO PROFORMA_SIPARISLER   \r\n");
                sb.Append("                                       (pro_RECid_DBCno, pro_RECid_RECno, pro_SpecRecNo, pro_iptal, pro_fileid, pro_hidden, pro_kilitli, pro_degisti,pro_checksum, pro_create_user,   \r\n");
                sb.Append("                                        pro_create_date, pro_lastup_user, pro_lastup_date, pro_special1,pro_special2,pro_special3,pro_firmano,pro_subeno,pro_tarihi,pro_testarihi,pro_tipi,pro_cinsi, pro_evrakno_seri,   \r\n");
                sb.Append("                                        pro_evrakno_sira, pro_satirno, pro_belge_no, pro_belge_tarihi,pro_saticikodu,pro_mustkodu, pro_stokkodu, pro_bfiyati, pro_miktar,pro_birim_pntr, pro_tesmiktari, pro_tutari , pro_iskonto1, pro_iskonto2, pro_iskonto3, pro_iskonto4, pro_iskonto5,pro_iskonto6,pro_masraf1,pro_masraf2,pro_masraf3,pro_masraf4, pro_vergipntr,   \r\n");
                sb.Append("                                        pro_vergi,pro_masrafvergipntr,pro_masrafvergi,pro_opno,pro_aciklama, pro_depono, pro_onaylayanKul_no,pro_vergisiz, pro_kapat,pro_cari_sormerk,pro_stok_sormerk, pro_dovizcinsi, pro_dovizkuru, pro_altdovizkuru, pro_adresno,pro_teslimturu, pro_cagrilabilir_fl,   \r\n");
                sb.Append("                                        pro_sipDbID, pro_sipRecID, pro_isk_mas_1,pro_isk_mas_2,pro_isk_mas_3,pro_isk_mas_4,pro_isk_mas_5,pro_isk_mas_6,pro_isk_mas_7,pro_isk_mas_8,pro_isk_mas_9,pro_isk_mas_10,pro_sat_isk_mas1,pro_sat_isk_mas2,pro_sat_isk_mas3,pro_sat_isk_mas4,pro_sat_isk_mas5,pro_sat_isk_mas6,pro_sat_isk_mas7,pro_sat_isk_mas8,pro_sat_isk_mas9,pro_sat_isk_mas10, \r\n");
                sb.Append("                                       pro_aciklama2,pro_Exp_Imp_Kodu,pro_karoani,pro_durumu, pro_stalRecId_DBCno, pro_stalRecId_RECno, pro_planlananmiktar,pro_teklifRecId_DBCno,pro_teklifRecId_RECno,pro_parti_kodu,pro_lot_no,pro_projekodu)  \r\n");
                sb.Append(" 		VALUES     (0,0, 0, 0, 22, 0, 0, 0,0,@kullanici,@Evrak_Tarih, @kullanici,@Evrak_Tarih,'','','',@firma_no,@sube_no,@Evrak_Tarih,@Evrak_Tarih, 1, 2, @Seri,@Sira,@Satir,'',@Evrak_Tarih,'',@Cari_kod,@Stok_kod, @Fiyat  , @Miktar  , 1,0, @yekun  ,@isk1_tutar,@isk2_tutar,@isk3_tutar,@isk4_tutar,@isk5_tutar,0,0,0,0,@kdv_tutar,@Kdv, 0,0,0,0,'',@GirisDepo, 0, 0, 0,@srmerkez,@srmerkez, 0, 1,1, 1,'', 1,0, 0,1,1,1,1,1,1,1,1,1,1, 0, 0, 0, 0,0,0,0,0,0,0,'','',0,0,0,0,0,0,0,'',0,'') \r\n");
                sb.Append(" 		SELECT @Record_id=SCOPE_IDENTITY() \r\n");
                sb.Append(" 		UPDATE    PROFORMA_SIPARISLER  SET   pro_RECid_RECno = @Record_id  WHERE    pro_RECno = @Record_id \r\n");
                sb.Append(" 	end \r\n");

                createQuery.Add(sb.ToString());
                #endregion

                #region TERMINAL_CHAR_EKLE
                createQuery.Add("if exists(Select * from sysobjects where xtype='p' and name='TERMINAL_CHAR_EKLE')  DROP  PROCEDURE [dbo].[TERMINAL_CHAR_EKLE]\r\n");

                sb = new StringBuilder();
                sb.Append(" CREATE   PROCEDURE [dbo].[TERMINAL_CHAR_EKLE] \r\n");
                sb.Append(" @cha_RECid_DBCno smallint, \r\n");
                sb.Append(" @cha_RECid_RECno int, \r\n");
                sb.Append(" @cha_SpecRecNo int, \r\n");
                sb.Append(" @cha_iptal bit, \r\n");
                sb.Append(" @cha_fileid smallint, \r\n");
                sb.Append(" @cha_hidden bit, \r\n");
                sb.Append(" @cha_kilitli bit, \r\n");
                sb.Append(" @cha_degisti bit, \r\n");
                sb.Append(" @cha_CheckSum int, \r\n");
                sb.Append(" @cha_create_user smallint,			  \r\n");
                sb.Append(" @cha_create_date datetime, \r\n");
                sb.Append(" @cha_lastup_user smallint, \r\n");
                sb.Append(" @cha_lastup_date datetime, \r\n");
                sb.Append(" @cha_special1 varchar(4), \r\n");
                sb.Append(" @cha_special2 varchar(4), \r\n");
                sb.Append(" @cha_special3 varchar(4), \r\n");
                sb.Append(" @cha_firmano int, \r\n");
                sb.Append(" @cha_subeno int, \r\n");
                sb.Append(" @cha_tarihi datetime, \r\n");
                sb.Append(" @cha_tip tinyint, \r\n");
                sb.Append(" @cha_cinsi tinyint, \r\n");
                sb.Append(" @cha_normal_Iade tinyint, \r\n");
                sb.Append(" @cha_evrak_tip tinyint, \r\n");
                sb.Append(" @cha_satir_no int, \r\n");
                sb.Append(" @cha_evrakno_seri varchar(5), \r\n");
                sb.Append(" @cha_evrakno_sira int, \r\n");
                sb.Append(" @cha_belge_no varchar(15), \r\n");
                sb.Append(" @cha_belge_tarih datetime, \r\n");
                sb.Append(" @cha_cari_cins tinyint, \r\n");
                sb.Append(" @cha_kod varchar(25), \r\n");
                sb.Append(" @cha_kasa_hizmet tinyint, \r\n");
                sb.Append(" @cha_kasa_hizkod varchar(25), \r\n");
                sb.Append(" @cha_d_kurtar datetime, \r\n");
                sb.Append(" @cha_d_cins tinyint, \r\n");
                sb.Append(" @cha_d_kur float, \r\n");
                sb.Append(" @cha_altd_kur float, \r\n");
                sb.Append(" @cha_grupno tinyint, \r\n");
                sb.Append(" @cha_meblag float, \r\n");
                sb.Append(" @cha_vade int, \r\n");
                sb.Append(" @cha_fis_tarih datetime, \r\n");
                sb.Append(" @cha_fis_sirano int, \r\n");
                sb.Append(" @cha_ft_iskonto1 float, \r\n");
                sb.Append(" @cha_ft_iskonto2 float, \r\n");
                sb.Append(" @cha_ft_iskonto3 float, \r\n");
                sb.Append(" @cha_ft_iskonto4 float, \r\n");
                sb.Append(" @cha_ft_iskonto5 float, \r\n");
                sb.Append(" @cha_ft_iskonto6 float, \r\n");
                sb.Append(" @cha_ft_masraf1 float, \r\n");
                sb.Append(" @cha_ft_masraf2 float, \r\n");
                sb.Append(" @cha_ft_masraf3 float, \r\n");
                sb.Append(" @cha_ft_masraf4 float, \r\n");
                sb.Append(" @cha_vergi1 float, \r\n");
                sb.Append(" @cha_vergi2 float, \r\n");
                sb.Append(" @cha_vergi3 float, \r\n");
                sb.Append(" @cha_vergi4 float, \r\n");
                sb.Append(" @cha_vergi5 float, \r\n");
                sb.Append(" @cha_vergi6 float, \r\n");
                sb.Append(" @cha_vergi7 float, \r\n");
                sb.Append(" @cha_vergi8 float, \r\n");
                sb.Append(" @cha_vergi9 float, \r\n");
                sb.Append(" @cha_vergi10 float, \r\n");
                sb.Append(" @cha_yuvarlama float, \r\n");
                sb.Append(" @cha_tpoz tinyint, \r\n");
                sb.Append(" @cha_aciklama varchar(40), \r\n");
                sb.Append(" @cha_trefno varchar(25), \r\n");
                sb.Append(" @cha_sntck_poz tinyint, \r\n");
                sb.Append(" @cha_karsidcinsi tinyint, \r\n");
                sb.Append(" @cha_karsid_kur float, \r\n");
                sb.Append(" @cha_karsidgrupno tinyint, \r\n");
                sb.Append(" @cha_srmrkkodu varchar(25), \r\n");
                sb.Append(" @cha_reftarihi datetime, \r\n");
                sb.Append(" @cha_odeme_arr1 float, \r\n");
                sb.Append(" @cha_odeme_arr2 float, \r\n");
                sb.Append(" @cha_odeme_arr3 float, \r\n");
                sb.Append(" @cha_odeme_arr4 float, \r\n");
                sb.Append(" @cha_odeme_arr5 float, \r\n");
                sb.Append(" @cha_odeme_arr6 float, \r\n");
                sb.Append(" @cha_odeme_arr7 float, \r\n");
                sb.Append(" @cha_odeme_arr8 float, \r\n");
                sb.Append(" @cha_miktari float, \r\n");
                sb.Append(" @cha_aratoplam float, \r\n");
                sb.Append(" @cha_vergipntr tinyint, \r\n");
                sb.Append(" @cha_istisnakodu tinyint, \r\n");
                sb.Append(" @cha_ver_tev_carpani float, \r\n");
                sb.Append(" @cha_stopaj float, \r\n");
                sb.Append(" @cha_savsandesfonu float, \r\n");
                sb.Append(" @cha_vergisiz_fl bit, \r\n");
                sb.Append(" @cha_satici_kodu varchar(25), \r\n");
                sb.Append(" @cha_mustahsil_borsa float, \r\n");
                sb.Append(" @cha_mustahsil_bagkur float, \r\n");
                sb.Append(" @cha_mustahsil_diger float, \r\n");
                sb.Append(" @cha_HalMSDF float, \r\n");
                sb.Append(" @cha_HalHamaliye float, \r\n");
                sb.Append(" @cha_HalStopaj float, \r\n");
                sb.Append(" @cha_HalKomisyonu float, \r\n");
                sb.Append(" @cha_StFonPntr tinyint, \r\n");
                sb.Append(" @cha_pos_hareketi bit, \r\n");
                sb.Append(" @cha_vardiya_tarihi datetime, \r\n");
                sb.Append(" @cha_vardiya_no tinyint, \r\n");
                sb.Append(" @cha_vardiya_evrak_ti tinyint, \r\n");
                sb.Append(" @cha_HalRusum float, \r\n");
                sb.Append(" @cha_HalNavlunTut float, \r\n");
                sb.Append(" @cha_HalRehinFuture float, \r\n");
                sb.Append(" @cha_HalKomisyon float, \r\n");
                sb.Append(" @cha_Vade_Farki_Yuz float, \r\n");
                sb.Append(" @cha_karsisrmrkkodu varchar(25), \r\n");
                sb.Append(" @cha_EXIMkodu varchar(25), \r\n");
                sb.Append(" @cha_HalRehinSandikmiktari float, \r\n");
                sb.Append(" @cha_HalSandikVrMiktar float, \r\n");
                sb.Append(" @cha_HalSandikTutari float, \r\n");
                sb.Append(" @cha_HalSandikKDVTutari float, \r\n");
                sb.Append(" @cha_HalrehinSandikTutari float, \r\n");
                sb.Append(" @cha_Tevkifat_turu tinyint, \r\n");
                sb.Append(" @cha_ticaret_turu tinyint, \r\n");
                sb.Append(" @cha_otvtutari float, \r\n");
                sb.Append(" @cha_otvvergisiz_fl bit, \r\n");
                sb.Append(" @cha_projekodu varchar(25), \r\n");
                sb.Append(" @cha_sozlesme_DBCno smallint, \r\n");
                sb.Append(" @cha_sozlesme_RECno int, \r\n");
                sb.Append(" @cha_yat_tes_kodu varchar(25), \r\n");
                sb.Append(" @cha_ciro_cari_kodu varchar(25), \r\n");
                sb.Append(" @cha_oivergisiz_fl bit, \r\n");
                sb.Append(" @cha_meblag_ana_doviz_icin_gecersiz_fl tinyint, \r\n");
                sb.Append(" @cha_meblag_alt_doviz_icin_gecersiz_fl tinyint, \r\n");
                sb.Append(" @cha_meblag_orj_doviz_icin_gecersiz_fl tinyint, \r\n");
                sb.Append(" @cha_ciroprim_DBCno smallint, \r\n");
                sb.Append(" @cha_ciroprim_RECno int, \r\n");
                sb.Append(" @cha_HalHamaliyeKdv float, \r\n");
                sb.Append(" @cha_HalHamaliyeVergisiz_fl bit \r\n");
                sb.Append(" as \r\n");
                sb.Append(" declare \r\n");
                sb.Append(" @Record_id int \r\n");
                sb.Append(" if exists(SELECT     cha_RECno  FROM         CARI_HESAP_HAREKETLERI  WHERE     (cha_evrak_tip = @cha_evrak_tip) AND (cha_evrakno_seri = @cha_evrakno_seri) AND (cha_evrakno_sira = @cha_evrakno_sira))  \r\n");
                sb.Append(" UPDATE    CARI_HESAP_HAREKETLERI  \r\n");
                sb.Append(" 	 SET              cha_RECid_DBCno =@cha_RECid_DBCno, cha_RECid_RECno =@cha_RECid_RECno, cha_SpecRecNo =@cha_SpecRecNo, cha_iptal =@cha_iptal, cha_fileid =@cha_fileid, cha_hidden =@cha_hidden, cha_kilitli =@cha_kilitli, cha_degisti =@cha_degisti, cha_CheckSum =@cha_CheckSum,  \r\n");
                sb.Append(" 					  cha_create_user =@cha_create_user, cha_create_date =@cha_create_date, cha_lastup_user =@cha_lastup_user, cha_lastup_date =@cha_lastup_date, cha_special1 =@cha_special1, cha_special2 =@cha_special2, cha_special3 =@cha_special3, cha_firmano =@cha_firmano, cha_subeno =@cha_subeno,  \r\n");
                sb.Append(" 					  cha_tarihi =@cha_tarihi, cha_tip =@cha_tip, cha_cinsi =@cha_cinsi, cha_normal_Iade =@cha_normal_Iade, cha_evrak_tip =@cha_evrak_tip , cha_satir_no =@cha_satir_no, cha_belge_no =@cha_belge_no, cha_belge_tarih =@cha_belge_tarih, cha_cari_cins =@cha_cari_cins, cha_kod =@cha_kod,  \r\n");
                sb.Append(" 					  cha_kasa_hizmet =@cha_kasa_hizmet, cha_kasa_hizkod =@cha_kasa_hizkod, cha_d_kurtar = @cha_d_kurtar, cha_d_cins =@cha_d_cins, cha_d_kur =@cha_d_kur, cha_altd_kur =@cha_altd_kur, cha_grupno =@cha_grupno, cha_meblag =@cha_meblag, cha_vade =@cha_vade, cha_fis_tarih =@cha_fis_tarih,  \r\n");
                sb.Append(" 					  cha_fis_sirano =@cha_fis_sirano, cha_ft_iskonto1 =@cha_ft_iskonto1, cha_ft_iskonto2 =@cha_ft_iskonto2, cha_ft_iskonto3 =@cha_ft_iskonto3, cha_ft_iskonto4 =@cha_ft_iskonto4, cha_ft_iskonto5 =@cha_ft_iskonto5, cha_ft_iskonto6 =@cha_ft_iskonto6, cha_ft_masraf1 =@cha_ft_masraf1,  \r\n");
                sb.Append(" 					  cha_ft_masraf2 =@cha_ft_masraf2, cha_ft_masraf3 =@cha_ft_masraf3, cha_ft_masraf4 =@cha_ft_masraf4, cha_vergi1 =@cha_vergi1, cha_vergi2 =@cha_vergi2, cha_vergi3 =@cha_vergi3, cha_vergi4 =@cha_vergi4, cha_vergi5 =@cha_vergi5, cha_vergi6 =@cha_vergi6, cha_vergi7 =@cha_vergi7, \r\n");
                sb.Append(" 					  cha_vergi8 =@cha_vergi8, cha_vergi9 =@cha_vergi9, cha_vergi10 =@cha_vergi10, cha_yuvarlama =@cha_yuvarlama, cha_tpoz =@cha_tpoz, cha_aciklama =@cha_aciklama, cha_trefno =@cha_trefno, cha_sntck_poz =@cha_sntck_poz, cha_karsidcinsi =@cha_karsidcinsi, cha_karsid_kur =@cha_karsid_kur,  \r\n");
                sb.Append(" 					  cha_karsidgrupno =@cha_karsidgrupno, cha_srmrkkodu =@cha_srmrkkodu, cha_reftarihi =@cha_reftarihi, cha_odeme_arr1 =@cha_odeme_arr1, cha_odeme_arr2 =@cha_odeme_arr2, cha_odeme_arr3 =@cha_odeme_arr3, cha_odeme_arr4 =@cha_odeme_arr4, cha_odeme_arr5 =@cha_odeme_arr5,  \r\n");
                sb.Append(" 					  cha_odeme_arr6 =@cha_odeme_arr6, cha_odeme_arr7 =@cha_odeme_arr7, cha_odeme_arr8 =@cha_odeme_arr8, cha_miktari =@cha_miktari, cha_aratoplam =@cha_aratoplam, cha_vergipntr =@cha_vergipntr, cha_istisnakodu =@cha_istisnakodu, cha_ver_tev_carpani =@cha_ver_tev_carpani, cha_stopaj =@cha_stopaj,  \r\n");
                sb.Append(" 					  cha_savsandesfonu =@cha_savsandesfonu, cha_vergisiz_fl =@cha_vergisiz_fl, cha_satici_kodu =@cha_satici_kodu, cha_mustahsil_borsa =@cha_mustahsil_borsa, cha_mustahsil_bagkur =@cha_mustahsil_bagkur, cha_mustahsil_diger =@cha_mustahsil_diger, cha_HalMSDF =@cha_HalMSDF,  \r\n");
                sb.Append(" 					  cha_HalHamaliye =@cha_HalHamaliye, cha_HalStopaj =@cha_HalStopaj, cha_HalKomisyonu =@cha_HalKomisyonu, cha_StFonPntr =@cha_StFonPntr, cha_pos_hareketi =@cha_pos_hareketi, cha_vardiya_tarihi =@cha_vardiya_tarihi, cha_vardiya_no =@cha_vardiya_no, cha_vardiya_evrak_ti =@cha_vardiya_evrak_ti,  \r\n");
                sb.Append(" 					  cha_HalRusum =@cha_HalRusum, cha_HalNavlunTut =@cha_HalNavlunTut, cha_HalRehinFuture =@cha_HalRehinFuture, cha_HalKomisyon =@cha_HalKomisyon, cha_Vade_Farki_Yuz =@cha_Vade_Farki_Yuz, cha_karsisrmrkkodu =@cha_karsisrmrkkodu, cha_EXIMkodu =@cha_EXIMkodu,  \r\n");
                sb.Append(" 					  cha_HalRehinSandikmiktari =@cha_HalRehinSandikmiktari, cha_HalSandikVrMiktar =@cha_HalSandikVrMiktar, cha_HalSandikTutari =@cha_HalSandikTutari, cha_HalSandikKDVTutari =@cha_HalSandikKDVTutari, cha_HalrehinSandikTutari =@cha_HalrehinSandikTutari, cha_Tevkifat_turu =@cha_Tevkifat_turu,  \r\n");
                sb.Append(" 					  cha_ticaret_turu =@cha_ticaret_turu, cha_otvtutari =@cha_otvtutari, cha_otvvergisiz_fl =@cha_otvvergisiz_fl, cha_projekodu =@cha_projekodu, cha_sozlesme_DBCno =@cha_sozlesme_DBCno, cha_sozlesme_RECno =@cha_sozlesme_RECno, cha_yat_tes_kodu =@cha_yat_tes_kodu,  \r\n");
                sb.Append(" 					  cha_ciro_cari_kodu =@cha_ciro_cari_kodu, cha_oivergisiz_fl =@cha_oivergisiz_fl, cha_meblag_ana_doviz_icin_gecersiz_fl =@cha_meblag_ana_doviz_icin_gecersiz_fl, cha_meblag_alt_doviz_icin_gecersiz_fl =@cha_meblag_alt_doviz_icin_gecersiz_fl,  \r\n");
                sb.Append(" 					  cha_meblag_orj_doviz_icin_gecersiz_fl =@cha_meblag_orj_doviz_icin_gecersiz_fl, cha_ciroprim_DBCno =@cha_ciroprim_DBCno, cha_ciroprim_RECno =@cha_ciroprim_RECno, cha_HalHamaliyeKdv =@cha_HalHamaliyeKdv, cha_HalHamaliyeVergisiz_fl =@cha_HalHamaliyeVergisiz_fl \r\n");
                sb.Append(" 	 WHERE     (cha_evrak_tip = @cha_evrak_tip) AND (cha_evrakno_seri = @cha_evrakno_seri) AND (cha_evrakno_sira = @cha_evrakno_sira) \r\n");
                sb.Append("  ELSE \r\n");
                sb.Append(" 	begin  \r\n");
                sb.Append(" 		INSERT INTO CARI_HESAP_HAREKETLERI  \r\n");
                sb.Append(" 						 (cha_RECid_DBCno, cha_RECid_RECno, cha_SpecRecNo, cha_iptal, cha_fileid, cha_hidden, cha_kilitli, cha_degisti, cha_CheckSum, cha_create_user,  \r\n");
                sb.Append(" 						 cha_create_date, cha_lastup_user, cha_lastup_date, cha_special1, cha_special2, cha_special3, cha_firmano, cha_subeno, cha_tarihi, cha_tip, cha_cinsi,  \r\n");
                sb.Append(" 						 cha_normal_Iade, cha_evrak_tip, cha_satir_no, cha_belge_no, cha_belge_tarih, cha_cari_cins, cha_kod, cha_kasa_hizmet, cha_kasa_hizkod, cha_d_kurtar,  \r\n");
                sb.Append(" 						 cha_d_cins, cha_d_kur, cha_altd_kur, cha_grupno, cha_meblag, cha_vade, cha_fis_tarih, cha_fis_sirano, cha_ft_iskonto1, cha_ft_iskonto2, cha_ft_iskonto3, \r\n");
                sb.Append(" 						 cha_ft_iskonto4, cha_ft_iskonto5, cha_ft_iskonto6, cha_ft_masraf1, cha_ft_masraf2, cha_ft_masraf3, cha_ft_masraf4, cha_vergi1, cha_vergi2, cha_vergi3, cha_vergi4, \r\n");
                sb.Append(" 						 cha_vergi5, cha_vergi6, cha_vergi7, cha_vergi8, cha_vergi9, cha_vergi10, cha_yuvarlama, cha_tpoz, cha_aciklama, cha_trefno, cha_sntck_poz, cha_karsidcinsi, \r\n");
                sb.Append(" 						 cha_karsid_kur, cha_karsidgrupno, cha_srmrkkodu, cha_reftarihi, cha_odeme_arr1, cha_odeme_arr2, cha_odeme_arr3, cha_odeme_arr4, cha_odeme_arr5, \r\n");
                sb.Append(" 						 cha_odeme_arr6, cha_odeme_arr7, cha_odeme_arr8, cha_miktari, cha_aratoplam, cha_vergipntr, cha_istisnakodu, cha_ver_tev_carpani, cha_stopaj, \r\n");
                sb.Append(" 						 cha_savsandesfonu, cha_vergisiz_fl, cha_satici_kodu, cha_mustahsil_borsa, cha_mustahsil_bagkur, cha_mustahsil_diger, cha_HalMSDF, cha_HalHamaliye, \r\n");
                sb.Append(" 						 cha_HalStopaj, cha_HalKomisyonu, cha_StFonPntr, cha_pos_hareketi, cha_vardiya_tarihi, cha_vardiya_no, cha_vardiya_evrak_ti, cha_HalRusum, cha_HalNavlunTut, \r\n");
                sb.Append(" 						 cha_HalRehinFuture, cha_HalKomisyon, cha_Vade_Farki_Yuz, cha_karsisrmrkkodu, cha_EXIMkodu, cha_HalRehinSandikmiktari, cha_HalSandikVrMiktar, \r\n");
                sb.Append(" 						 cha_HalSandikTutari, cha_HalSandikKDVTutari, cha_HalrehinSandikTutari, cha_Tevkifat_turu, cha_ticaret_turu, cha_otvtutari, cha_otvvergisiz_fl, cha_projekodu, \r\n");
                sb.Append(" 						 cha_sozlesme_DBCno, cha_sozlesme_RECno, cha_yat_tes_kodu, cha_ciro_cari_kodu, cha_oivergisiz_fl, cha_meblag_ana_doviz_icin_gecersiz_fl,  \r\n");
                sb.Append(" 						 cha_meblag_alt_doviz_icin_gecersiz_fl, cha_meblag_orj_doviz_icin_gecersiz_fl, cha_ciroprim_DBCno, cha_ciroprim_RECno, cha_HalHamaliyeKdv,cha_HalHamaliyeVergisiz_fl,cha_evrakno_seri,cha_evrakno_sira) \r\n");
                sb.Append(" 		 VALUES  (0,-999,@cha_SpecRecNo,@cha_iptal,@cha_fileid,@cha_hidden,@cha_kilitli,@cha_degisti,@cha_CheckSum,@cha_create_user, \r\n");
                sb.Append(" 						 @cha_create_date,@cha_lastup_user,@cha_lastup_date,@cha_special1,@cha_special2,@cha_special3,@cha_firmano,@cha_subeno,@cha_tarihi,@cha_tip,@cha_cinsi, \r\n");
                sb.Append(" 						 @cha_normal_Iade,@cha_evrak_tip,@cha_satir_no,@cha_belge_no,@cha_belge_tarih,@cha_cari_cins,@cha_kod,@cha_kasa_hizmet,@cha_kasa_hizkod,@cha_d_kurtar, \r\n");
                sb.Append(" 						 @cha_d_cins,@cha_d_kur,@cha_altd_kur,@cha_grupno,@cha_meblag,@cha_vade,@cha_fis_tarih,@cha_fis_sirano,@cha_ft_iskonto1,@cha_ft_iskonto2,@cha_ft_iskonto3, \r\n");
                sb.Append(" 						 @cha_ft_iskonto4,@cha_ft_iskonto5,@cha_ft_iskonto6,@cha_ft_masraf1,@cha_ft_masraf2,@cha_ft_masraf3,@cha_ft_masraf4,@cha_vergi1,@cha_vergi2,@cha_vergi3,@cha_vergi4, \r\n");
                sb.Append(" 						 @cha_vergi5,@cha_vergi6,@cha_vergi7,@cha_vergi8,@cha_vergi9,@cha_vergi10,@cha_yuvarlama,@cha_tpoz,@cha_aciklama,@cha_trefno,@cha_sntck_poz,@cha_karsidcinsi, \r\n");
                sb.Append(" 						 @cha_karsid_kur,@cha_karsidgrupno,@cha_srmrkkodu,@cha_reftarihi,@cha_odeme_arr1,@cha_odeme_arr2,@cha_odeme_arr3,@cha_odeme_arr4,@cha_odeme_arr5, \r\n");
                sb.Append(" 						 @cha_odeme_arr6,@cha_odeme_arr7,@cha_odeme_arr8,@cha_miktari,@cha_aratoplam,@cha_vergipntr,@cha_istisnakodu,@cha_ver_tev_carpani,@cha_stopaj, \r\n");
                sb.Append(" 						 @cha_savsandesfonu,@cha_vergisiz_fl,@cha_satici_kodu,@cha_mustahsil_borsa,@cha_mustahsil_bagkur,@cha_mustahsil_diger,@cha_HalMSDF,@cha_HalHamaliye, \r\n");
                sb.Append(" 						 @cha_HalStopaj,@cha_HalKomisyonu,@cha_StFonPntr,@cha_pos_hareketi,@cha_vardiya_tarihi,@cha_vardiya_no,@cha_vardiya_evrak_ti,@cha_HalRusum,@cha_HalNavlunTut, \r\n");
                sb.Append(" 						 @cha_HalRehinFuture,@cha_HalKomisyon,@cha_Vade_Farki_Yuz,@cha_karsisrmrkkodu,@cha_EXIMkodu,@cha_HalRehinSandikmiktari,@cha_HalSandikVrMiktar, \r\n");
                sb.Append(" 						 @cha_HalSandikTutari,@cha_HalSandikKDVTutari,@cha_HalrehinSandikTutari,@cha_Tevkifat_turu,@cha_ticaret_turu,@cha_otvtutari,@cha_otvvergisiz_fl,@cha_projekodu, \r\n");
                sb.Append(" 						 @cha_sozlesme_DBCno,@cha_sozlesme_RECno,@cha_yat_tes_kodu,@cha_ciro_cari_kodu,@cha_oivergisiz_fl,@cha_meblag_ana_doviz_icin_gecersiz_fl, \r\n");
                sb.Append(" 						 @cha_meblag_alt_doviz_icin_gecersiz_fl,@cha_meblag_orj_doviz_icin_gecersiz_fl,@cha_ciroprim_DBCno,@cha_ciroprim_RECno,@cha_HalHamaliyeKdv,@cha_HalHamaliyeVergisiz_fl,@cha_evrakno_seri,@cha_evrakno_sira) \r\n");
                sb.Append(" 		UPDATE    CARI_HESAP_HAREKETLERI SET   cha_RECid_RECno = SCOPE_IDENTITY()  WHERE    cha_RECno = SCOPE_IDENTITY() \r\n");
                sb.Append(" 		if @cha_tip =0 and @cha_cinsi =6 and @cha_normal_Iade =0 and @cha_evrak_tip =63 \r\n");
                sb.Append("             begin \r\n");
                sb.Append(" 			    select    @Record_id=cha_RECno FROM CARI_HESAP_HAREKETLERI WITH(NOLOCK) WHERE     (cha_evrak_tip = 63) AND (cha_evrakno_seri = @cha_evrakno_seri) AND (cha_evrakno_sira = @cha_evrakno_sira) \r\n");
                sb.Append(" 			    UPDATE    STOK_HAREKETLERI  SET   sth_fat_recid_dbcno = 0,sth_fat_recid_recno=@Record_id WHERE     (sth_tip = 1) AND (sth_cins = 0) AND (sth_normal_iade = 0) AND (sth_evraktip = 4) AND (sth_evrakno_seri = @cha_evrakno_seri) AND (sth_evrakno_sira = @cha_evrakno_sira) \r\n");
                sb.Append("             end \r\n");
                sb.Append(" 		else \r\n");
                sb.Append("             begin \r\n");
                sb.Append(" 			    select    @Record_id=cha_RECno FROM CARI_HESAP_HAREKETLERI WITH(NOLOCK)WHERE     (cha_evrak_tip = 0) AND (cha_evrakno_seri = @cha_evrakno_seri) AND (cha_evrakno_sira = @cha_evrakno_sira) \r\n");
                sb.Append(" 			    UPDATE    STOK_HAREKETLERI  SET   sth_fat_recid_dbcno = 0,sth_fat_recid_recno=@Record_id WHERE     (sth_tip = 0) AND (sth_cins = 0) AND (sth_normal_iade = 1) AND (sth_evraktip = 3) AND (sth_evrakno_seri = @cha_evrakno_seri) AND (sth_evrakno_sira = @cha_evrakno_sira) \r\n");
                sb.Append("             end \r\n");
                sb.Append(" end \r\n");

                createQuery.Add(sb.ToString());
                #endregion

                #region TERMINAL_ALINANSIPARIS_EKLE
                createQuery.Add("if exists(Select * from sysobjects where xtype='p' and name='TERMINAL_ALINANSIPARIS_EKLE') DROP  PROCEDURE [dbo].[TERMINAL_ALINANSIPARIS_EKLE]\r\n");

                sb = new StringBuilder();
                sb.Append(" CREATE  PROCEDURE [dbo].[TERMINAL_ALINANSIPARIS_EKLE] \r\n");
                sb.Append(" @Evrak_Tarih DateTime, \r\n");
                sb.Append(" @Seri VarChar(5), \r\n");
                sb.Append(" @Sira int, \r\n");
                sb.Append(" @Satir Int, \r\n");
                sb.Append(" @Stok_kod VarChar(25), \r\n");
                sb.Append(" @Cari_kod VarChar(25), \r\n");
                sb.Append(" @Miktar Float, \r\n");
                sb.Append(" @GirisDepo int, \r\n");
                sb.Append(" @CikisDepo int, \r\n");
                sb.Append(" @plasiyer varchar(25), \r\n");
                sb.Append(" @srmerkez varchar(25), \r\n");
                sb.Append(" @kullanici varchar(25), \r\n");
                sb.Append(" @yekun Float, \r\n");
                sb.Append(" @isk1_tutar Float, \r\n");
                sb.Append(" @isk2_tutar Float, \r\n");
                sb.Append(" @isk3_tutar Float, \r\n");
                sb.Append(" @isk4_tutar Float, \r\n");
                sb.Append(" @isk5_tutar Float, \r\n");
                sb.Append(" @Kdv TinyInt, \r\n");
                sb.Append(" @Fiyat Float, \r\n");
                sb.Append(" @belge_no varchar(25), \r\n");
                sb.Append(" @firma_no int, \r\n");
                sb.Append(" @sube_no int, \r\n");
                sb.Append(" @doviz_cinsi int, \r\n");
                sb.Append(" @doviz_kur float \r\n");
                sb.Append(" AS \r\n");
                sb.Append(" DECLARE \r\n");
                sb.Append(" @Record_id int, \r\n");
                sb.Append(" @kdv_oran float, \r\n");
                sb.Append(" @kdv_tutar float \r\n");
                sb.Append(" set @kdv_oran=dbo.fn_VergiYuzde(@Kdv) \r\n");
                sb.Append(" set @kdv_tutar = (@yekun - (@isk1_tutar+@isk2_tutar+@isk3_tutar+@isk4_tutar+@isk5_tutar)) * @kdv_oran / 100 \r\n");
                sb.Append(" if exists(SELECT     sip_evrakno_seri  FROM         SIPARISLER  WHERE     (sip_evrakno_seri = @Seri) AND (sip_evrakno_sira =@Sira) AND (sip_satirno = @Satir) AND (sip_tip = 0) AND (sip_cins=0)) \r\n");
                sb.Append(" 	begin \r\n");
                sb.Append(" 		UPDATE SIPARISLER SET \r\n");
                sb.Append(" 									sip_lastup_user=@kullanici, sip_lastup_date=@Evrak_Tarih, sip_tarih=@Evrak_Tarih, sip_teslim_tarih=@Evrak_Tarih, sip_tip=0, sip_cins=0, sip_evrakno_seri=@Seri,   \r\n");
                sb.Append("                                        sip_evrakno_sira=@Sira, sip_satirno=@Satir, sip_belge_tarih=@Evrak_Tarih, sip_musteri_kod=@Cari_kod, sip_stok_kod=@Stok_kod, sip_b_fiyat= @Fiyat, sip_miktar=@Miktar, sip_teslim_miktar=0, sip_tutar=@yekun , sip_iskonto_1=@isk1_tutar, sip_iskonto_2=@isk2_tutar, sip_iskonto_3=@isk3_tutar, sip_iskonto_4=@isk4_tutar, sip_iskonto_5=@isk5_tutar , sip_vergi_pntr=@Kdv,sip_vergi=@kdv_tutar, \r\n");
                sb.Append("                                         sip_opno=0, sip_depono=@GirisDepo, sip_vergisiz_fl=0, sip_kapat_fl=0, sip_doviz_cinsi=@doviz_cinsi, sip_doviz_kuru=@doviz_kur, sip_alt_doviz_kuru=1, sip_adresno=0, sip_cagrilabilir_fl=1,   \r\n");
                sb.Append("                                        sip_prosiprecDbId=0, sip_prosiprecrecI=0, sip_durumu=0, sip_stalRecId_DBCno=0, sip_stalRecId_RECno=0, sip_planlananmiktar=0,sip_iskonto1=1, sip_iskonto2=1, sip_iskonto3=1, sip_iskonto4=1, sip_iskonto5=1,sip_stok_sormerk=@srmerkez,sip_cari_sormerk=@srmerkez,sip_belgeno=@belge_no,sip_firmano=@firma_no,sip_subeno=@sube_no,sip_harekettipi=0 \r\n");
                sb.Append(" 		WHERE     (sip_evrakno_seri = @Seri) AND (sip_evrakno_sira =@Sira) AND (sip_satirno = @Satir) AND (sip_tip = 0) AND (sip_cins=0) \r\n");
                sb.Append(" 	end \r\n");
                sb.Append(" else \r\n");
                sb.Append(" 	begin \r\n");
                sb.Append(" 		INSERT INTO SIPARISLER   \r\n");
                sb.Append("                                       (sip_RECid_DBCno, sip_RECid_RECno, sip_SpecRECno, sip_iptal, sip_fileid, sip_hidden, sip_kilitli, sip_checksum, sip_create_user,   \r\n");
                sb.Append("                                        sip_create_date, sip_lastup_user, sip_lastup_date, sip_tarih, sip_teslim_tarih, sip_tip, sip_cins, sip_evrakno_seri,   \r\n");
                sb.Append("                                        sip_evrakno_sira, sip_satirno, sip_belge_tarih, sip_musteri_kod, sip_stok_kod, sip_b_fiyat, sip_miktar, sip_teslim_miktar, sip_tutar , sip_iskonto_1, sip_iskonto_2, sip_iskonto_3, sip_iskonto_4, sip_iskonto_5, sip_vergi_pntr,sip_vergi, \r\n");
                sb.Append("                                         sip_opno, sip_depono, sip_vergisiz_fl, sip_kapat_fl, sip_doviz_cinsi, sip_doviz_kuru, sip_alt_doviz_kuru, sip_adresno, sip_cagrilabilir_fl,   \r\n");
                sb.Append("                                        sip_prosiprecDbId, sip_prosiprecrecI, sip_durumu, sip_stalRecId_DBCno, sip_stalRecId_RECno, sip_planlananmiktar,sip_iskonto1, sip_iskonto2, sip_iskonto3, sip_iskonto4, sip_iskonto5,sip_stok_sormerk,sip_cari_sormerk,sip_belgeno,sip_firmano,sip_subeno,sip_harekettipi)  \r\n");
                sb.Append("                         VALUES     (0,0, 0, 0, 21, 0, 0, 0, @kullanici,@Evrak_Tarih, @kullanici,@Evrak_Tarih,@Evrak_Tarih,@Evrak_Tarih, 0, 0, @Seri,@Sira,@Satir,@Evrak_Tarih,@Cari_kod,@Stok_kod, @Fiyat  , @Miktar  , 0, @yekun  , @isk1_tutar  , @isk2_tutar  , @isk3_tutar  , @isk4_tutar  , @isk5_tutar  ,@Kdv,@kdv_tutar, 0,@GirisDepo, 0, 0, @doviz_cinsi, @doviz_kur, 1, 0, 1, 0, 0, 0, 0, 0, 0,1,1,1,1,1,@srmerkez,@srmerkez,@belge_no,@firma_no,@sube_no,0) \r\n");
                sb.Append(" 		SELECT @Record_id=SCOPE_IDENTITY() \r\n");
                sb.Append(" 		UPDATE    SIPARISLER    SET   sip_RECid_RECno = @Record_id  WHERE    sip_RECno = @Record_id \r\n");
                sb.Append(" 	end \r\n");

                createQuery.Add(sb.ToString());
                #endregion

                #region Cari Bakiye
                createQuery.Add("if exists(Select * from sysobjects where xtype='FN' and name='fn_WinSatCariBakiye') DROP  FUNCTION [dbo].[fn_WinSatCariBakiye]\r\n");
                createQuery.Add("CREATE  FUNCTION [dbo].[fn_WinSatCariBakiye](@CARIKODU as Varchar(25)) RETURNS float AS  BEGIN  RETURN dbo.fn_CariHesapAnaDovizBakiye('',0,@CARIKODU,'','',NULL,NULL,NULL,0) END\r\n");
                #endregion

                //#region Satis Sartı için fonksiyon
                //createQuery.Add("if exists(Select * from sysobjects where xtype='FN' and name='fn_winsat_satis_sarti_fiyati') DROP  FUNCTION [dbo].[fn_winsat_satis_sarti_fiyati]\r\n");

                //StringBuilder fn = new StringBuilder();
                //fn.Append(" CREATE FUNCTION [dbo].[fn_winsat_satis_sarti_fiyati](@carikod as varchar(25),@stokkod as varchar(25),@depono as int,@tarih as varchar(8))     \r\n");
                //fn.Append(" RETURNS float     \r\n");
                //fn.Append(" AS     \r\n");
                //fn.Append(" BEGIN \r\n");
                //fn.Append(" DECLARE \r\n");
                //fn.Append(" @fiyat float, \r\n");
                //fn.Append(" @carifiyatno int \r\n");
                //fn.Append(" 	SELECT TOP 1 @fiyat=(sat_brut_fiyat -(sat_det_isk_miktar1+sat_det_isk_miktar2+sat_det_isk_miktar3+sat_det_isk_miktar4+sat_det_isk_miktar5+sat_det_isk_miktar6) + (sat_det_mas_miktar1+sat_det_mas_miktar2+sat_det_mas_miktar3+sat_det_mas_miktar4)) \r\n");
                //fn.Append(" 	FROM SATIS_SARTLARI WITH (NOLOCK, INDEX = NDX_SATIS_SARTLARI_03)  \r\n");
                //fn.Append(" 	WHERE (sat_cari_kod=@carikod AND  sat_stok_kod=@stokkod AND  sat_basla_tarih<=@tarih AND (sat_bitis_tarih>=@tarih OR sat_bitis_tarih<='19101231')  AND sat_depo_no=@depono) \r\n");
                //fn.Append(" 	ORDER BY sat_basla_tarih DESC, sat_bitis_tarih DESC \r\n");
                //fn.Append(" if @fiyat <=0 or @fiyat is null \r\n");
                //fn.Append(" 	SELECT TOP 1 @fiyat=(sat_brut_fiyat -(sat_det_isk_miktar1+sat_det_isk_miktar2+sat_det_isk_miktar3+sat_det_isk_miktar4+sat_det_isk_miktar5+sat_det_isk_miktar6) + (sat_det_mas_miktar1+sat_det_mas_miktar2+sat_det_mas_miktar3+sat_det_mas_miktar4)) \r\n");
                //fn.Append(" 	FROM SATIS_SARTLARI WITH (NOLOCK, INDEX = NDX_SATIS_SARTLARI_03)  \r\n");
                //fn.Append(" 	WHERE (sat_cari_kod=@carikod AND  sat_stok_kod=@stokkod AND  sat_basla_tarih<=@tarih AND (sat_bitis_tarih>=@tarih OR sat_bitis_tarih<='19101231')  AND (sat_depo_no=0 or sat_depo_no is NULL))  \r\n");
                //fn.Append(" 	ORDER BY sat_basla_tarih DESC, sat_bitis_tarih DESC \r\n");
                //fn.Append(" if @fiyat <=0 or @fiyat is null \r\n");
                //fn.Append(" begin \r\n");
                //fn.Append(" 	select @carifiyatno=cari_satis_fk from CARI_HESAPLAR where cari_kod =@carikod \r\n");
                //fn.Append(" 	set @fiyat= cast(dbo.fn_StokSatisFiyati(@stokkod,1,@depono) as varchar(10)) + ';0;0;0;0;0' \r\n");
                //fn.Append(" end \r\n");
                //fn.Append(" if @fiyat is null set @fiyat=0 \r\n");
                //fn.Append(" return @fiyat \r\n");
                //fn.Append(" END \r\n");

                //createQuery.Add(fn.ToString());
                //#endregion
            }

            StringBuilder sb2 = new StringBuilder();
            foreach (string query in createQuery)
            {
                sb2.AppendLine(query);
            }

            File.WriteAllText("sorgu.txt",sb2.ToString());

            using (SqlConnection sql = new SqlConnection(Config.GetConfig.GetValue(CParams.ConStr)))
            {
                sql.Open();
                foreach (string query in createQuery)
                {
                    using (SqlCommand cmd = new SqlCommand(query, sql))
                    {
                        try
                        {
                            cmd.ExecuteNonQuery();
                        }
                        catch (Exception ex)
                        {
                            System.Windows.Forms.MessageBox.Show(ex.Message);
                        }
                    }
                }
                sql.Close();
            }

        }

        #region IDisposable Members

        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }

        #endregion
    }
}
